package com.xxl.job.executor.jobhandler.impl.integral;

import com.xxl.job.executor.jobhandler.impl.EveryDayExecute;
import com.xxl.job.sscIntegrInfo.service.ISscIntegrInfoService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.interceptor.TransactionAspectSupport;

/**
 * 积分任务定时器
 *
 * @author : zyc
 * @version : 1.0
 * @create : 2023/09/01 11:24
 **/
@Component
public class IntLostEfficacyExecute implements EveryDayExecute {

    private static final Logger log = LoggerFactory.getLogger(IntLostEfficacyExecute.class);

    @Autowired
    private ISscIntegrInfoService iSscIntegrInfoService;

    /**
      * 任务积分未领取已失效, 定时更新 [积分状态为已失效]
      *
      * @author: zyc
      * @date: 2023/9/1 11:39
      */
    @Transactional(rollbackFor = Exception.class)
    @Override
    public void execute() {
        try {
            int count = iSscIntegrInfoService.updateInlLoseEfficacy();
            log.info("-- 已更新失效积分 [" + count + "] 条");
        } catch (Exception e) {
            e.printStackTrace();
            log.error("更新失效积分数据出现异常 : " + e);
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
        }
    }
}
